import rxAjax from '@/assets/ajax.js';
export const FormApi = {};
FormApi.formSolution = function (alias,pk,action,params){
    let url= '/api-form/form/core/formSolution/mobile/' + alias +'?pk='+pk+"&action="+action;
    return rxAjax.postJson(url,params).then (res => {
        return res
    })
}

FormApi.getSolutionByAlias=function(alias,id,action,params) {
    let url= "/api-form/form/core/formSolution/" + alias + '/getByAlias'  ;
    let args=["isMobile=true"];
    if(id){
        args.push("pk=" + id);
    }
    if(action){
        args.push("action=" + action);
    }
    if(args.length>0){
        url+="?" + args.join("&");
    }
    return rxAjax.postJson(url,params);
}

FormApi.saveForm = function (params){
    let url= '/api-form/form/core/formSolution/saveForm';
    return rxAjax.postJson(url,params).then (res => {
        return res
    })
}
/**
 * 自定义SQL
 */
FormApi.queryForJson=function(sqlKey,params){
    let url= "/api-form/form/core/formCustomQuery/queryForJson_"+sqlKey;
    return rxAjax.postForm(url,params).then(res=>{
        return res;
    });
}

/**
 *根据表单数据获取按钮集合
 * @param formSolutionAlias
 * @param formJson
 * @returns {*}
 */
FormApi.getButtonsByFormJson=function(formSolutionAlias,formJson){
    let url = '/api-form/form/core/formSolution/getButtonsByFormJson?formSolutionAlias='+formSolutionAlias+"&isMobile=true";
    return rxAjax.postJson(url,formJson);
}

//验证二维码配置
FormApi.validQrcode=function(qrcode, qrCodeAuth,alias,pkId,appId) {
    let url= '/api-form/form/core/formQrcodeConfig/validQrcode?qrcode='+qrcode +"&qrCodeAuth="+qrCodeAuth +"&alias="+alias +"&pkId="+pkId+"&appId="+appId;
    return rxAjax.get(url,{needToken:false})
}

//二维码保存表单(未登录)
FormApi.saveQrcodeForm=function (params,qrcodeId){
    let url= '/api-form/form/core/formQrcodeConfig/saveQrcodeForm?qrcodeId='+qrcodeId ;
    return rxAjax.postJson(url,params);
}

/**
 * 执行规则引擎
 * @param liteFlowId
 * @param params
 * @returns {*}
 */
FormApi.executeLiteFlow =function(liteFlowId, params) {
    let url= '/api-form/form/core/formLiteFlow/executeLiteFlow?liteFlowId='+liteFlowId;
    return rxAjax.postJson(url,params);
}


export default FormApi
